<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户注册页面</title>
    <jsp:include page="../part/css/register.jsp" flush="true"/>
    <jsp:include page="../part/js/register.jsp" flush="true"/>
</head>
<body>

<form action="${pageContext.request.contextPath}/user/edit" method="post" onsubmit="return handleSubmit()">
    <h2 class="title">欢迎来到用户修改页面</h2>
    <span class="form-item-label"> 用户名</span> <input class="form-item" type="text" readonly name="username"
                                                        value="${user.username}"
                                                        placeholder="请输入用户名">
    <span></span>
    <c:if test="${!empty updateResult.errors.username}">
        <span class="error-msg">${updateResult.errors.username}</span>
    </c:if>
    <c:if test="${empty updateResult.errors.username}">
        <span class="hidden">错误提示</span>
    </c:if>


    <span class="form-item-label">密码</span><input class="form-item" type="password" name="password"
                                                    placeholder="请输入密码">
    <span></span>
    <c:if test="${!empty updateResult.errors.password}">
        <span class="error-msg">${updateResult.errors.password}</span>
    </c:if>
    <c:if test="${empty updateResult.errors.password}">
        <span class="hidden">错误提示</span>
    </c:if>

    <span class="form-item-label">邮箱</span><input class="form-item" type="email" name="email" value="${user.email}"
                                                    placeholder="请输入邮箱">
    <span></span>
    <c:if test="${!empty updateResult.errors.email}">
        <span class="error-msg">${updateResult.errors.email}</span>
    </c:if>
    <c:if test="${empty updateResult.errors.email}">
        <span class="hidden">错误提示</span>
    </c:if>


    <span class="form-item-label">手机号</span><input class="form-item" type="text" name="mobile" value="${user.mobile}"
                                                      placeholder="请输入手机号">
    <span></span>
    <c:if test="${!empty updateResult.errors.mobile}">
        <span class="error-msg">${updateResult.errors.mobile}</span>
    </c:if>
    <c:if test="${empty updateResult.errors.mobile}">
        <span class="hidden">错误提示</span>
    </c:if>


    <span class="form-item-label">用户类型</span>
    <select class="form-item" name="type">

        <c:if test="${user.type == 1}">
            <option value="1" selected>普通用户</option>
            <option value="2">管理员</option>
        </c:if>

        <c:if test="${user.type == 2}">
            <option value="1">普通用户</option>
            <option value="2" selected>管理员</option>
        </c:if>

    </select>
    <input class="form-btn" type="submit" value="提交修改">
    <input class="form-btn" type="reset" value="重置">
    <span class="to-login"><a href="${pageContext.request.contextPath}/user/list"> 返回列表页</a></span>
    <input type="hidden" name="repeat_code" value="${repeat_code}">
    <input type="hidden" name="id" value="${user.id}">

</form>

<script type="text/javascript">

    function handleSubmit() {

        let loading = layer.showLoading("正在提交请稍后", null, () => {

        })

        function login(success, error) {

            if (success) {
                success();
            }
            if (error) {
                error();
            }
        }

        let dotLen = 1;
        let interval = setInterval(function () {
            // 防止dotLen大于3
            if (dotLen > 3) {
                dotLen = 1;
            }

            // 根据dotLen生成 ... 优雅的方式
            let dots = "";
            for (let i = 0; i < dotLen; i++) {
                dots += ".";
            }
            loading.setMsg("正在提交请稍后" + dots);
            dotLen++;

        }, 1000);


        return true;
    }
</script>
</body>
</html>
